<?php





/**
 * @Author:      lyt
 * @DateTime:    2015-10-16 10:34:35
 * @Description: 用于维护门店 工位的model
 *//**
  * @Author:      lyt
  * @DateTime:    2015-12-29 15:42:15
  * @Description: Description
  */

class MaintenanceStation extends Eloquent
{

  protected $table = "maintenance_station";

  public static $status = array(
    "1"=>"开启",
    "0"=>"关闭",
  );


  public function stype(){
    return $this->hasOne('MaintenanceStationType',"id","type");
  }

  /**
   * @Author:      lyt
   * @DateTime:    2015-10-16 10:35:25
   * @Description: 参数数组 用于保存一个 维修店工位的信息
   */  
  public static function saveByDate($date){
  	$ms=new MaintenanceStation();
  	$ms->name=strtoupper($date['name']);
    $ms->status=$date['status'];
    $ms->shop_id=$date['shop_id'];
    $ms->type=$date['type'];
    $ms->save();

    $msc=new MaintenanceStationCar();
    $msc->shop_id=$ms->shop_id;
    $msc->station_id=$ms->id;
    $msc->car_no="";
    $msc->status=0;
    $msc->save();
    return $ms;
  }    

  /**
   * @Author:      lyt
   * @DateTime:    2016-01-12 13:52:37
   * @Description: 查看车位是是否空闲 空闲返回true
   */
  public static function isFree($id){
    $msc=MaintenanceStationCar::where("station_id",$id)->first();
    return $msc->status==0;
  }    

}
